package com.sangzc.orc;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import org.json.JSONArray;
import org.json.JSONObject;

import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Sample1 {

    public static void main(String[] args) {
        String readString = FileUtil.readString("C:\\Users\\Administrator.JTTLL-F0IR20S\\Desktop\\新建文本文档.json",Charset.forName("UTF-8"));
        //System.out.println(readString);
        JSONObject jsonObject = new JSONObject(readString);
        JSONObject words_result = jsonObject.getJSONObject("words_result");
        System.out.println(words_result.getString("InvoiceDate"));//开票日期
        System.out.println(words_result.getString("InvoiceNum"));//发票号码
        //SellerName	是	string	销售方名称
        System.out.println(words_result.getString("SellerName"));
        //CommodityName	是	object	货物名称
        JSONArray commodityName = words_result.getJSONArray("CommodityName");
        String x = commodityName.toString();
        System.out.println(x);
        Pattern p = Pattern.compile("\\*(.*?)\\*");//正则表达式，取=和|之间的字符串，不包括=和|
        Matcher m = p.matcher(x);
        while(m.find()) {
            System.out.println(m.group(1));//m.group(1)不包括这两个字符
        }
       // TotalAmount	是	uint32	合计金额
        System.out.println(words_result.getString("TotalAmount"));
        //TotalTax	是	uint32	合计税额
        System.out.println(words_result.getString("TotalTax"));
        //AmountInFiguers	是	uint32	价税合计(小写)
        System.out.println(words_result.getString("AmountInFiguers"));
      /*  String filetext = "//@张小名: 25分//@李小花: 43分//@王力: 100分";
        Pattern p = Pattern.compile("\\@(.*?)\\:");//正则表达式，取=和|之间的字符串，不包括=和|
        Matcher m = p.matcher(filetext);
        while(m.find()) {
            System.out.println(m.group(0));//m.group(1)不包括这两个字符
        }*/

    }
}
